/**
 * Created by Administrator on 2018/10/8.
 */
+function ($) {
    var ExtiCheck = function (f, e) {
        this.$element =  $(f);
        this.options = $.extend({}, ExtiCheck.DEFAULTS, this.$element.data(), e);
        this.init()
    };
    ExtiCheck.DEFAULTS = {
        checkboxClass: 'icheckbox_square-blue',
         radioClass: 'iradio_square-blue',
        increaseArea: '20%' // optional

    }
    ExtiCheck.prototype.init = function () {
        var $element = this.$element ,
            id = $element.attr('id'),
            name = $element.attr('name'),
            label = $element.attr('label')

        if (label) $element.after('<label for="' + id + '" class="ilabel">' + label + '</label>')

        $element
            .on('ifCreated', function (e) {
                /* Fixed validate msgbox position */
                var $parent = $(this).closest('div'),
                    $ilabel = $parent.next('[for="' + id + '"]')
                $parent.attr('data-icheck', name)
                $ilabel.attr('data-icheck', name)
            })
            .on('ifChanged', function () {
                /* Trigger validation */
                $.fn.validator && $(this).trigger('validate')
            })
            .iCheck(this.options)


        if ($element.prop('disabled')) $element.iCheck('disable')
    }
    function Plugin(e) {
        Bolt.assert($.fn.iCheck, "依赖组件 iCheck 未引入");
        return this.each(function () {
            var h = $(this);
            var g = h.data("extiCheck");
            var f = typeof e == "object" && e;
            if (!g) {
                h.data("extiCheck", (g = new ExtiCheck(this, f)))
            }
            if (typeof e == "string") {
                g[e]()
            }
        })
    }
    $.fn.extiCheck = Plugin
    $.fn.extiCheck.Constructor = ExtiCheck;

    Bolt.addComponent({
        name: "ExtiCheck",
        plugin: Plugin,
        runPoint: Bolt.eventType.afterAjaxPageShow,
        expr: "input[data-toggle='iCheck']",
        order: 800
    })
}(jQuery);
